'use strict';
let express = require('express');
let router = express.Router();
let request = require('request');
let fs = require('fs'); 
let base_url=process.env.SERVER_URL||'http://api.readedu.cn';
let API={
	ajax:function(opt){
		//eval(config);
		request({
		    url: base_url + opt.url,
		    method: opt.type||"get",
		    json: true,
		    headers: {"content-type": "application/json",token:opt.token||""},
		    body: opt.data
		}, function(error,res,body) {
		    if (!error && res.statusCode == 200) {
		    	opt.success(body);
		    }else{
		    	if(opt.error){
		    		opt.error(body);
		    	}    	
		    }
		}); 
	}
};
router.API=API;
module.exports = router;
